<template>
  <div>
    <!-- 查询插件 -->
        <!-- 查询插件 -->
    <div>
      <el-form ref="queryParams" :model="queryParams" :inline="true" label-width="80px">
        

        <el-form-item label="省份">
          <el-input v-model="queryParams.province"></el-input>
        </el-form-item>


        <!-- <el-form-item label="收入：">
          <el-input v-model="queryParams.startincome"></el-input>
        </el-form-item>

        <el-form-item label="————">
          <el-input v-model="queryParams.endincome"></el-input>
        </el-form-item> -->

        <el-form-item>
          <el-button type="primary" @click="searchStudent">查询</el-button>
          <el-button type="primary" @click="RentCarAdd">新增</el-button>
        </el-form-item>
      </el-form>
    </div>

    <!-- stu展示插件 -->
    <div>
      <el-table :data="pageBean.beanList" border style="width: 100%">
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column prop="financeid" label="财务编号"></el-table-column>
        <el-table-column prop="province" label="省份名字"></el-table-column>
        <el-table-column prop="allmoney" label="总共钱数"></el-table-column>
        <el-table-column prop="disbursemoney" label="贷出资金"></el-table-column>
        <el-table-column prop="income" label="收回资金"></el-table-column>
        

        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
            <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!-- 分页插件 -->
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageBean.pageIndex"
        :page-sizes="[3, 4, 5, 6,10]"
        :page-size="pageBean.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pageBean.totalRecord"
      ></el-pagination>
    </div>


  <!-- 添加故障的模态框 -->
     





    <!-- 模态框插件 -->
    
    <div>
      <el-dialog :title="title" :visible.sync="dialogFormVisible" @close="closeDialog">
        <el-form
          ref="eitParams"
          :model="eitParams"
          :inline="true"
          label-width="80px"
          :rules="rules"
        >
          <!-- <el-form-item label="门店信息id" prop="storeid">
          <el-input v-model="eitParams.storeid"></el-input>
          </el-form-item>-->
          <el-form-item label="省份" prop="province" label-width="120px">
            <el-input v-model="eitParams.province"></el-input>
          </el-form-item>
          <el-form-item label="总共资金" prop="allmoney" label-width="120px">
            <el-input v-model="eitParams.allmoney"></el-input>
          </el-form-item>
          <el-form-item label="支出资金" prop="disbursemoney" label-width="120px">
            <el-input v-model="eitParams.disbursemoney"></el-input>
          </el-form-item>
          <el-form-item label="收入资金" prop="income" label-width="120px">
            <el-input v-model="eitParams.income"></el-input>
          </el-form-item>

      
        </el-form>

        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="updatestu('eitParams')">确 定</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>


<script>
//导入axios
import axios from "axios";

export default {
  data() {
    return {
      // tableData: [],
      pageIndex: 1,
      pageSize: 10,
      pageBean: {
        beanList: [],
        pageIndex: 0,
        pageSize: 0,
        totalRecord: 0,
        totalPage: 0
      },
      role: [],
      dept: [],
      // RentCarInfotwo: [],
      // parking: [],
      // rentcarType: [],
      rules: {
        // storeid: [
        //   { required: true, message: '请输入活动名称', trigger: 'blur' },
        //   { min: 1, max: 10, message: '长度在 1 到 10个字符', trigger: 'blur' }
        // ],
        //  operation_state: [
        //   { required: true, message: '请输年龄', trigger: 'blur' },
        //   { min: 1, max: 10, message: '长度在 1 到 10个字符', trigger: 'blur' }
        // ],
        rentcarprice: [
          { required: true, message: "请输年龄", trigger: "blur" },
          { min: 1, max: 10, message: "长度在 1 到 10个字符", trigger: "blur" }
        ]
        //  car_typeid: [
        //   { required: true, message: '请输年龄', trigger: 'blur' },
        //   { min: 1, max: 10, message: '长度在 1 到 10个字符', trigger: 'blur' }
        // ],
        // car_numbe: [
        //   { required: true, message: '请输年龄', trigger: 'blur' },
        //   { min: 1, max: 10, message: '长度在 1 到 10个字符', trigger: 'blur' }
        // ],
        // mailbox_capacity: [
        //   { required: true, message: '请输年龄', trigger: 'blur' },
        //   { min: 1, max: 10, message: '长度在 1 到 10个字符', trigger: 'blur' }
        // ],
        //  seating: [
        //   { required: true, message: '请输年龄', trigger: 'blur' },
        //   { min: 1, max: 10, message: '长度在 1 到 10个字符', trigger: 'blur' }
        // ],
        //  carkm: [
        //   { required: true, message: '请输年龄', trigger: 'blur' },
        //   { min: 1, max: 10, message: '长度在 1 到 10个字符', trigger: 'blur' }
        // ],
      },
      
      queryParams: {
         province: "",
       startincome: "",
        endincome:"",
      },
     
      eitParams: {
       province: "",
         allmoney: "",
        disbursemoney: "",
        income: "",
      },
      AddParams: {
        warn_cause: "",
        rentcarid: "",
        warn_time: "",
        process_state:"",
        empid:"",
      },
      dialogFormVisible: false,
      dialogFormVisibletwo:false,
      title: ""
    };
  },
  created() {
    //生命周期方法
     this.getstaffList();
    // this.getrole();
    // this.getdept();
    // 
  },
  methods: {
   
    updatestu(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          if (valid) {
            if (this.title == "编辑") {
              this.$axios
                .put("http://localhost:8601/finance/updateFinance", this.eitParams)
                .then(resp => {
                  
                  if(resp.data.code==500){
                this.$message("你没有操作权限");
              }else{
                 this.$message("修改成功");
              }
                  
                  this.dialogFormVisible = false;
                   this.getstaffList();
                });
            } else {
              this.$axios
                .post("http://localhost:8601/finance/addFinance", this.eitParams)
                .then(resp => {
                   if(resp.data.code==500){
                this.$message("你没有操作权限");
              }else{
                this.$message("添加成功");
              }
                  
                  this.dialogFormVisible = false;
                  this.getstaffList();
                });
            }
          } else {
            console.log("error submit!!");
            return false;
          }

          //     this.$axios.put("http://localhost:8080/updateRenrCarIn/", this.eitParams).
          //  then(resp=>{
          //   this.$message("修改成功");
          //   this.dialogFormVisible=false;
          //   this.getStudents();
          //  });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    handAddWarn(){
       this.dialogFormVisibletwo = true;
        this.AddParams = { ...row };
    },
    handleEdit(index, row) {
      console.log(index, row);
     
      this.dialogFormVisible = true;
      // this.getStudents();
      this.eitParams = { ...row };
      //  this.eitParams.parkid=row.parking.parkname;
      //  this.eitParams.car_typeid=row.rentCarType.cartype_name;
      this.title = "编辑";
    },
    handleDelete(index, row) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$axios
            .delete("http://localhost:8601/finance/delFinance/" + row.financeid)
            .then(resp => {
              console.log(resp.data);
              if(resp.data.code==500){
                this.$message("你没有操作权限");
              }else{
                 this.$message("删除成功");
              }
              this.getstaffList();
            });
          // this.$message({
          //   type: "success",
          //   message: "删除成功!"
          // });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    
    

    

    // getrole() {
    //   this.$axios
    //     .get("http://localhost:8601/staff/getallRole", {
    //       params: {
    //         // pageIndex: this.pageIndex,
    //         // pageSize: this.pageSize,
    //       }
    //     })
    //     .then(resp => {
    //       this.role = resp.data;
    //       // console.log(this.province)
    //     });
    // },
    // getdept() {
    //   this.$axios
    //     .get("http://localhost:8601/staff/getallDept", {
    //       params: {
    //         // pageIndex: this.pageIndex,
    //         // pageSize: this.pageSize,
    //       }
    //     })
    //     .then(resp => {
    //       this.dept = resp.data;
    //       // console.log(this.province)
    //     });
    // },

   getstaffList() {
      this.$axios
        .get("http://localhost:8601/finance/getallFinance", {
          params: {
            pageIndex: this.pageIndex,
            pageSize: this.pageSize,
          province: this.queryParams.province,
          // startincome: this.queryParams.startincome,
          // endincome:this.queryParams.endincome,
          //  did:this.queryParams.did,
          // //  status:this.queryParams.status,
          //  starttime:this.queryParams.starttime,
          //  endtime: this.queryParams.endtime,
          //  username:this.queryParams.username
 

         
            
          }
        })
        .then(resp => {
          console.log(resp.data)
          if(resp.data.code==500){
               this.$router.push('/');
          }else{
            this.pageBean = resp.data.data;
          }
          
          
        });
    },
    searchStudent() {
      this.getstaffList();
    },
    switchChange(data){
       this.$axios
            .put("http://localhost:8080/updateRenrCarInbyrentcarid/" + data.rentcarid)
            .then(resp => {
              console.log("修改成功");
              this.getstaffList();
            });
          this.$message({
            type: "success",
            message: "修改成功!"
          });
    },
    RentCarAdd() {
      (this.title = "新增"), (this.dialogFormVisible = true);
      // this.$axios
      //   .get("http://localhost:8080/getRentCarType/")
      //   .then(resp => {
      //     console.log(resp);
      //   });
      //  this.$router.push("RentCarAdd");
      //  this.title="新增",
      //  this.dialogFormVisible=true
    },
    closeDialog() {
      console.log("模态框关闭");
      this.eitParams = {};
      this.$refs["eitParams"].clearValidate();
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageSize = val;
      this.getstaffList();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.pageIndex = val;
      this.getstaffList();
    }
  }
};
</script>

<style>
</style>
